﻿<%@ Page Language="C#" %>

<%@ Register Assembly="PeekEditor" Namespace="PeekEditor" TagPrefix="PeekEditor" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
    <link href="../../Styles/jquery.validate.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/jquery.validate.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.validator.messages.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../Scripts/jquery.query.js"></script>
    <script src="../../ckeditor/ckeditor.js" type="text/javascript"></script>
    <script src="../../ckfinder/ckfinder.js" type="text/javascript"></script>
    <script src="../js/blockUI.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server" method="post" action="../AjaxHandler/CountriesRegionEditHandler.ashx?action=Edit">
    <div>
        <table>
            <tr>
                <td>
                    国家
                </td>
                <td>
                    <input type="text" id="country" name="country" />
                </td>
            </tr>
            <tr>
                <td>
                    省
                </td>
                <td>
                    <input id="province" rows="5" cols="20" name="province" />
                </td>
            </tr>
            <tr>
                <td>
                    市（城市）
                </td>
                <td>
                    <input id="city"  name="city"  type="text"/>
                </td>
            </tr>
            <tr>
                <td>
                    说明
                </td>
                <td>
                    <PeekEditor:CKEditorControl ID="remark" runat="server" />
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <input type="submit" id="btn_Save" value="保 存" /><input type="button" id="btn_Back"
                        value="返 回" onclick="javascript:history.back();" />
                </td>
            </tr>
        </table>
    </div>
    <input id="hidCode" name="hidCode" type="hidden" value="-1" />
    </form>
    <script type="text/javascript">

        $(document).ready(function () {

            var code = $.query.get("code");
            $("#hidCode").val(code);
            function SetEditorContents(EditorName, ContentStr) { var oEditor = CKEDITOR.instances[EditorName]; oEditor.setData(ContentStr); }
            var BindData = function () {
                if (code != "-1") {
                    $.blockUI({ message: "<h2>数据加载中.......</h2>", css: { width: "300px", height: "50px"} });
                    $.post("../AjaxHandler/CountriesRegionEditHandler.ashx", { action: "Get", hidCode: code }, function (data) {
                        $("#country").val(data.Country);
                        $("#province").val(data.Province);
                        $("#city").val(data.City);
                        SetEditorContents("remark", data.Remark);
                        $.unblockUI();
                    });
                }

            }
            BindData();

            $("#form1").validate({
                rules: {
                    country: { required: true },
                    province: { required: true },
                    city: { required: true,
                        remote: {
                            type: "POST",
                            url: "../AjaxHandler/CountriesRegionEditHandler.ashx",
                            data: { action: "Check", country: function () { return $("#country").val(); }, province: function () { return $("#province").val(); }, city: function () { return $("#city").val(); },hidCode:code }
                        }
                    }
                },
                messages:{
                        country: { required: "请输入国家！" },
                        province: { required: "请输入省份！" },
                        city: { required: "请输入城市！", remote: "该城市已经存在！" }
                         }
            });

        });
    </script>
</body>
</html>
